package main

import (
	"fmt"
	"math"
)

func main() {
	a, b := 4, 3
	fmt.Println(add(a, b))

	fmt.Println(foo(a, b))

	swap(&a, &b)
	fmt.Println(a, b)

	//函数变量
	val := func(x float64) float64 {
		return math.Pow(x, 2)
	}

	fmt.Println(val(3))

	fmt.Println("闭包")
	nex := getSequence()
	fmt.Println(nex())
	fmt.Println(nex())
}

func add(a int, b int) int {
	c := a * b
	return c
}

//返回多参数
func foo(a, b int) (int, int) {
	return a * b, a + b
}

//引用传参
func swap(a *int, b *int) {
	tmp := *a
	*a = *b
	*b = tmp
}

//闭包
func getSequence() func() int {
	i := 0
	return func() int {
		i += 1
		return i
	}

}
